package com.wwlwxg.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

/**
 * 订阅频道
 */
public class PubSubSubscribe extends JedisPubSub {

	static Jedis jedis = new Jedis("localhost", 6379);

	public static void main(String[] args) throws Exception {
		try {
			PubSubSubscribe mySubscriber = new PubSubSubscribe();
			String channel = "MyChannel";
			jedis.subscribe(mySubscriber, channel);
		}finally {
			jedis.close();
		}
	}

	// Receive messages
	@Override
	public void onMessage(String channel, String message) {
		System.out.println(message);
	}
}